package com.jprocms.module.cms.controller.admin.site.vo;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import static com.jprocms.module.cms.framework.constant.CommonConstants.PATH_SPLIT;

@Schema(description = "管理后台 - 站点 精简信息树 Response VO")
@Data
@EqualsAndHashCode
@ToString(callSuper = true)
public class SiteSimpleRespVO {

    @Schema(description = "编号", required = true, example = "1024")
    private Long id;

    @Schema(description = "名称", required = true, example = "泽睿")
    private String name;

    @Schema(description = "父ID", required = true, example = "1024")
    private Long parentId;

    @Schema(description = "id路径拼接")
    private String nodePath;

    /**
     * 获取层级
     *
     * @return
     */
    public int getDeep() {
        String nodePath = getNodePath();
        if (StringUtils.isBlank(nodePath)) {
            return 1;
        }
        String[] nodeIdArr = nodePath.split(PATH_SPLIT);
        return nodeIdArr.length == 0 ? 1 : nodeIdArr.length;
    }

}
